﻿using System.Windows.Forms;
using Map;
using Map_Creator.MapInfo;
using Map_Creator.RedoUndo;

namespace Map_Creator.AnimatedTileEditor
{
    public partial class AnimatedTileEditor : Form
    {
        public AnimatedTile TileResult;
        
        private TileSet tileSet;

        public AnimatedTileEditor(TileSet set, AnimatedTileStruct animatedTile)
        {
            InitializeComponent();

            tileSet = set;
            
            TileSetControl.Initialize(tileSet);
            AnimationStrip.Initialize(animatedTile, tileSet ,TileSetControl, ControlsBox.RedoUndoStrip);
            AnimationStrip.Height = tileSet.AssociatedMap.TileSize;
            TileSetPanel.Width = tileSet.TilesImage.Width + SystemInformation.VerticalScrollBarWidth;
            TileSetControl.Width = tileSet.TilesImage.Width;
            TileSetControl.Height = tileSet.TilesImage.Height;

            ControlsBox.SaveButton.Click += Save_OnClick;
            ControlsBox.RedoUndoStrip.OnRedoUndo +=OnRedoUndo;
        }

        private void OnRedoUndo(IRedoUndo actionhandler, IAction action)
        {
            AnimationStrip.Invalidate();
        }

        private void Save_OnClick(object sender, System.EventArgs e)
        {
            DialogResult = DialogResult.OK;
            TileResult = AnimationStrip.GetAnimatedTile();
        }
    }
}